package org.bartcr.tools.io.scanner;

import org.apache.commons.io.DirectoryWalker;
import org.apache.commons.io.filefilter.IOFileFilter;

import java.io.File;
import java.io.IOException;
import java.util.*;

class ScannerDirectoryWalker extends DirectoryWalker<File> {
    ScannerDirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter) {
        super(directoryFilter, fileFilter, -1);
    }

    public Set<File> list(File basedir) {
        Set<File> result = new HashSet<File>();
        try {
            walk(basedir, result);
        } catch (IOException ignore) {
            ignore.printStackTrace();
        }
        return result;
    }

    @Override
    protected void handleFile(File file, int depth, Collection<File> results) throws IOException {
        results.add(file);
    }
}
